package com.tpfinal.agenda.core.mysqlrequests;

import java.sql.SQLException;
import java.util.Map;

import com.tpfinal.agenda.core.AgendaActionParamsCodes;
import com.tpfinal.agenda.core.AgendaActionsIDs;
import com.tpfinal.agenda.model.Contact;

public class DeleteContactRequest extends MySqlBaseRequest {

	private static final String QUERY = "DELETE FROM contactos WHERE %s=%s";

	@Override
	public int getID() {
		return AgendaActionsIDs.DELETE_CONTACT;
	}

	@Override
	protected void setup(Map<String, Object> params) {

		this.queryType = QUERY_TYPE_UPDATE;

		Contact c = (Contact) params.get(AgendaActionParamsCodes.PARAM_CONTACT);

		this.sqlQuery = String.format(QUERY, MySQL.MYSQL_COLUMN_ID, c.getId());

		System.out.println(this.sqlQuery);

	}

	@Override
	protected Map<String, Object> processResult(Map<String, Object> resultSet) {

		try {
			connection.close();
			resultSet.put(RESULT_CODE, OK);
		} catch (SQLException e) {
			e.printStackTrace();
			resultSet.put(RESULT_CODE, ERROR);
		}
		return resultSet;
	}

}
